class Solution {
public:
    bool IsPopOrder(vector<int>& pushV, vector<int>& popV)
    {
        vector<int> test;
        reverse(pushV.begin(), pushV.end());
        reverse(popV.begin(), popV.end());
        int size = popV.size();
        for (int i = 0; i < size; i++)
        {
            test.push_back(pushV.back());
            pushV.pop_back();
            while (!test.empty() && (test.back() == popV.back()))
            {
                test.pop_back(); popV.pop_back();
            }
        }
        return test.empty();
    }
};